package com.dunqi.gpm.shunqing.common.api;

import com.dunqi.gpm.shunqing.WPConfig;
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import com.dunqi.gpm.shunqing.common.api.gson.GsonConverterFactory;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

/**
 * @author 空
 * @date 2017/6/8 0008
 */

public class ApiFactory {
    private static OkHttpClient httpClient = new OkHttpClient.Builder()
            .addInterceptor(new LoggingInterceptor())
            .addInterceptor(new HeaderInterceptor())
            .connectTimeout(60, TimeUnit.SECONDS)
            .readTimeout(60, TimeUnit.SECONDS)
            .cookieJar(CookiesManager.getInstence())
            .build();
    private static ApiService apiService = new Retrofit.Builder()
            .baseUrl(WPConfig.baseUrl)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .client(httpClient)
            .build()
            .create(ApiService.class);

    public static ApiService getInstance() {
        return apiService;
    }
}
